precision mediump float;
uniform sampler2D u_texture;
uniform sampler2D u_displace;
uniform sampler2D u_mask;
uniform float u_time;
varying vec2 v_uv;
void main()
{
	float dMax = 0.05;
	float startAtV = 0.0;
	vec4 mask  = texture2D(u_mask, v_uv);
	
	if (v_uv.y < startAtV)
	{
		vec4 disp_tex = texture2D(u_texture, v_uv);	
		gl_FragColor = disp_tex * vec4(1.0, 1.0, 1.0, mask.r);		
	}
	else
	{	
		vec2 displace = texture2D(u_displace, vec2(v_uv.s, v_uv.t + u_time)).rg;
		vec2 offset = (2.0 * displace - 1.0) * dMax;
		vec4 disp_tex = texture2D(u_texture, v_uv + offset);
		gl_FragColor = disp_tex * vec4(1.0, 1.0, 1.0, mask.r);	
	}
}
